package com.example.mypigcar.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author yzl
 * @date 2021/5/21 12:27
 * @Description: 创建Uuid
 */
public class UUIDUtils {

    /**
     * 生成32位随机字符
     */
    public static String getUUID() {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        return uuid;
    }

    /**
     * 生成自定义长度的随机字符
     *
     * @param num 长度
     */
    public static String getUUID(int num) {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, num);
        return uuid;
    }

    /**
     * 生成数字和大写字母组成的随机字符
     */
    public static String getUpperUUID() {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
        return uuid;
    }

    /**
     * 生成自定义长度数字和大写字母的随机字符
     */
    public static String getUpperUUID(int num) {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, num).toUpperCase();
        return uuid;
    }

    /**
     * 生成6位随机数字验证码
     */
    public static String getCaptcha() {
        Random random = new Random();
        String captcha = "";
        for (int i = 0; i < 6; i++) {
            String s = String.valueOf(random.nextInt(9) + 1);
            captcha += s;
        }
        return captcha;
    }


}
